<template>

  <div>
    <!-- 幻灯片 开始 -->
    <div v-swiper:mySwiper="swiperOption">
      <div class="swiper-wrapper">
        <div
          v-for="banner in banners"
          :key="banner.id"
          :style="`background: ${banner.color};`"
          class="swiper-slide">
          <a :href="banner.linkUrl" target="_blank">
            <img :src="banner.imageUrl" :alt="banner.title" width="65%">
          </a>
        </div>
      </div>
      <div class="swiper-pagination swiper-pagination-white"/>
      <div slot="button-prev" class="swiper-button-prev swiper-button-white"/>
      <div slot="button-next" class="swiper-button-next swiper-button-white"/>
    </div>
    <!-- 幻灯片 结束 -->

    <div id="aCoursesList">
      <!-- 网校课程 开始 -->
      <div>
        <section class="container">
          <header class="comm-title">
            <h2 class="tac">
              <span class="c-333">热门课程</span>
            </h2>
          </header>
          <div>
            <article class="comm-course-list">
              <ul id="bna" class="of">
                <li v-for="course in courses" :key="course.id">
                  <div class="cc-l-wrap">
                    <section class="course-img">
                      <img
                        :src="course.cover"
                        :alt="course.title"
                        class="img-responsive"
                      >
                      <div class="cc-mask">
                        <a
                          :title="course.title"
                          :href="`/course/${course.id}`"
                          class="comm-btn c-btn-1">开始学习</a>
                      </div>
                    </section>
                    <h3 class="hLh30 txtOf mt10">
                      <a
                        :title="course.title"
                        :href="`/course/${course.id}`"
                        class="course-title fsize18 c-333">{{ course.title }}</a>
                    </h3>
                    <section class="mt10 hLh20 of">
                      <span class="fr jgTag bg-green">
                        <i class="c-fff fsize12 f-fA">{{ course.price===0?'免费':'¥'+course.price }}</i>
                      </span>
                      <span class="fl jgAttr c-ccc f-fA">
                        <i class="c-999 f-fA">{{ course.viewCount }}人学习</i>
                        |
                        <i class="c-999 f-fA">{{ course.buyCount }}购买</i>
                      </span>
                    </section>
                  </div>
                </li>

              </ul>
              <div class="clear"/>
            </article>
            <section class="tac pt20">
              <a href="/course" title="全部课程" class="comm-btn c-btn-2">全部课程</a>
            </section>
          </div>
        </section>
      </div>
      <!-- /网校课程 结束 -->
      <!-- 网校名师 开始 -->
      <div>
        <section class="container">
          <header class="comm-title">
            <h2 class="tac">
              <span class="c-333">名师大咖</span>
            </h2>
          </header>
          <div>
            <article class="i-teacher-list">
              <ul class="of">
                <li v-for="teacher in teachers" :key="teacher.id">
                  <section class="i-teach-wrap">
                    <div class="i-teach-pic">
                      <a
                        :href="`/teacher/${teacher.id}`"
                        :title="teacher.name">
                        <img
                          :alt="teacher.name"
                          :src="teacher.avatar?teacher.avatar:'https://oss.aliyuncs.com/aliyun_id_photo_bucket/default_handsome.jpg?imageView2/1/w/80/h/80'"
                          width="142">
                      </a>
                    </div>
                    <div class="mt10 hLh30 txtOf tac">
                      <a
                        :href="`/teacher/${teacher.id}`"
                        :title="teacher.name"
                        class="fsize18 c-666">{{ teacher.name }}</a>
                    </div>
                  </section>
                </li>

              </ul>
              <div class="clear"/>
            </article>
            <section class="tac pt20">
              <a href="/teacher" title="全部讲师" class="comm-btn c-btn-2">全部讲师</a>
            </section>
          </div>
        </section>
      </div>
      <!-- /网校名师 结束 -->
    </div>
  </div>
</template>

<script>
import adApi from '~/api/ad'
export default {
  data() {
    return {
      banners: [],
      courses: [],
      teachers: [],

      swiperOption: {
        // 配置分页
        pagination: {
          el: '.swiper-pagination'// 分页的dom节点
        },
        // 配置导航
        navigation: {
          nextEl: '.swiper-button-next', // 下一页dom节点
          prevEl: '.swiper-button-prev'// 前一页dom节点
        }
      }
    }
  },
  // async asyncData() {
  //   const res = await adApi.getHotAds()
  //   return {
  //     banners: res.data.map.banners,
  //     courses: res.data.map.courses,
  //     teachers: res.data.map.teachers
  //   }
  // },
  created() {
    adApi.getHotAds().then(res => {
      this.banners = res.data.map.banners
      this.courses = res.data.map.courses
      this.teachers = res.data.map.teachers
    })
  }
}
</script>
